<template>
	<view>
		<city-select placeholder="搜索城市" :formatName="formatName" :obtainCitys="obtainCitys" :isSearch="true"
			:activeCity="activeCity" :hotCity="hotCity" @cityClick="chooseCity"></city-select>
	</view>
</template>

<script>
	import citySelect from '@/components/city-select/city-select.vue'
	import {
		operatingCity
	} from '@/api/home-api.js'
	export default {
		components: {
			citySelect
		},
		data() {
			return {
				formatName: 'cityName',
				//当前城市
				activeCity: {
					cityId: this.$store.state.user.locationCityCode,
					cityName: this.$store.state.user.locationCity,
				},
				//显示的城市数据
				obtainCitys: [],
				type: 1, //1取车 2还车
			}
		},
		computed: {
			businessNo() {
				return this.$store.state.order.businessNo;
			}
		},
		onLoad(op) {
			this.type = op.type;
			this.getCityList();
		},
		methods: {
			getCityList() {
				operatingCity({
					tenantId: this.$store.state.user.tenantId,
				}).then(res => {
					this.obtainCitys = res.data;
				})
			},
			chooseCity(item) {
				console.log(this.businessNo);
				if (this.businessNo == 1 || this.businessNo == 3) {//短租|豪车
					if (this.type == 1) { //短租取车城市
						//更新取车城市信息
						this.$store.commit("user/saveCity", item.cityName);
						this.$store.commit("user/saveAddress", '请选择');
						this.$store.commit("user/saveCityCode", item.cityId);
					} else if (this.type == 2) { //短租还车城市
						//更新还车城市信息
						this.$store.commit("user/saveReturnCity", item.cityName);
						this.$store.commit("user/saveReturnAddress", '请选择');
						this.$store.commit("user/saveReturnCityCode", item.cityId);
					}
				}else if(this.businessNo == 2){//长租城市
					this.$store.commit("order/savelStoreName", '请选择');
					this.$store.commit("user/saveLCityId", item.cityId);
					this.$store.commit("user/savelCityName", item.cityName);
					console.log(item);
					
				}
				uni.$emit('refreshCity', item);
				uni.navigateBack({

				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
